import moment from 'moment'
import dt from '@dt/dt'

function examine(status, name) {
  let data = []
  if (name === 'levelApprovalManager') {
    data = [{
      field: 'auditStateStr',
      title: '审批状态',
      minWidth: 100
    }, {
      field: 'nextChecker',
      title: '当前审批节点',
      minWidth: 160
    }]
  } else {
    if (status != '0') {
      data = [{
        field: 'auditName',
        title: '审批人',
        minWidth: 100,
      }, {
        title: '审批日期',
        minWidth: 120,
        cell: {
          value: (row) => moment(row.auditTime).format('YYYY-MM-DD'),
          text: {}
        }
      }]
    }
    if (status == '2') {
      data.push({
        field: 'auditReason',
        title: '驳回原因',
        minWidth: 150,
      })
    }
  }
  return data
}

function options(status, name) {
  return [
    {
      type: 'index',
      title: '序号',
      minWidth: 70
    },
    {
      field: 'orgName',
      title: '所属组织',
      minWidth: 150,
    },
    {
      field: 'housesName',
      title: '案场名称',
      minWidth: 160,
    },
    {
      field: 'auditData.rankPointsName',
      title: '职级点数模板名称',
      minWidth: 180
    },
    {
      field: 'auditData.effectiveDate',
      title: '生效日期',
      minWidth: 210,
    },
    {
      field: 'auditData.isJumpPoint',
      title: '是否跳点',
      minWidth: 90,
    },
    {
      field: 'submitName',
      title: '提交人',
      minWidth: 100,
    },
    {
      title: '提交日期',
      minWidth: 120,
      cell: {
        value: (row) => moment(row.submitTime).format('YYYY-MM-DD'),
        text: {}
      }
    },
    ...examine(status, name),
    {
      field: 'handles',
      title: '操作',
      width: 140,
      fixed: 'right',
      cell: (row) => {
        if (name === 'levelApprovalManager') {
          return {
            btn: [{
              title: '查看',
              event: 'onDetail'
            },{
              title: '流程信息',
              event: 'onFlow'
            }]
          }
        } else {
          return {
            btn: [{
              title: '查看',
              event: 'onDetail'
            }, {
              title: status == '0' ? '审批' : '',
              event: 'onAudit',
              code: '0206050201'
            }]
          }
        }
      }
    }
  ]
}

export default {
  options
}
